1 | from django.db import models |
---|
2 | |
---|
3 | import datetime |
---|
4 | |
---|
5 | import settings |
---|
6 | import groups.models |
---|
7 | from util.misc import log_and_ignore_failures |
---|
8 | |
---|
9 | class FYSM(models.Model): |
---|
10 | group = models.ForeignKey(groups.models.Group) |
---|
11 | display_name = models.CharField(max_length=50) |
---|
12 | year = models.IntegerField() |
---|
13 | website = models.URLField() |
---|
14 | join_url = models.URLField(help_text="If you have a specific web page for students interested in joining your group, you can link to it here. If you leave this blank it will default to your website.") |
---|
15 | contact_email = models.EmailField(help_text="Give an address for students interested in joining the group to email (e.g., an officers list)") |
---|
16 | description = models.TextField(help_text="Explain in about three or four sentences what your group does and why incoming freshmen should get involved.") |
---|
17 | logo = models.ImageField(upload_to='fysm/logos', blank=True, ) |
---|
18 | tags = models.CharField(max_length=100, blank=True, help_text="Specify some free-form, comma-delimited tags for your group", ) |
---|
19 | categories = models.ManyToManyField('FYSMCategory', blank=True, help_text="Put your group into whichever of our categories seem applicable.", ) |
---|
20 | |
---|
21 | class Meta: |
---|
22 | verbose_name = "FYSM submission" |
---|
23 | |
---|
24 | class FYSMCategory(models.Model): |
---|
25 | name = models.CharField(max_length=10) |
---|
26 | slug = models.SlugField() |
---|
27 | blurb = models.TextField() |
---|
28 | |
---|
29 | def __str__(self, ): |
---|
30 | return self.name |
---|
31 | |
---|
32 | class Meta: |
---|
33 | verbose_name = "FYSM category" |
---|
34 | verbose_name_plural = "FYSM categories" |
---|
35 | |
---|
36 | class FYSMView(models.Model): |
---|
37 | fysm = models.ForeignKey(FYSM, blank=True, ) |
---|
38 | year = models.IntegerField(null=True, blank=True, ) |
---|
39 | page = models.CharField(max_length=20, blank=True, ) |
---|
40 | referer = models.URLField(verify_exists=False) |
---|
41 | user_agent = models.CharField(max_length=255) |
---|
42 | source_ip = models.IPAddressField() |
---|
43 | source_user = models.CharField(max_length=30, blank=True, ) |
---|
44 | |
---|
45 | @staticmethod |
---|
46 | @log_and_ignore_failures(logfile=settings.LOGFILE) |
---|
47 | def record_metric(request, fysm=None, year=None, page=None, ): |
---|
48 | record = FYSMView() |
---|
49 | record.fysm = fysm |
---|
50 | record.year = year |
---|
51 | record.page = page |
---|
52 | record.referer = request.META['HTTP_REFERER'] |
---|
53 | record.user_agent = request.META['HTTP_USER_AGENT'] |
---|
54 | record.source_ip = request.META['REMOTE_ADDR'] |
---|
55 | record.source_user = request.user.username |
---|
56 | record.save() |
---|